package dao;

import entity.Onligne;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import org.hibernate.LockMode;
import org.hibernate.Query;
import static org.hibernate.criterion.Example.create;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * Onligne entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see entity.Onligne
 * @author MyEclipse Persistence Tools
 */

@Stateless
@LocalBean
public class OnligneDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(OnligneDAO.class);

	public void save(Onligne transientInstance) {
		log.debug("saving Onligne instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Onligne persistentInstance) {
		log.debug("deleting Onligne instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Onligne findById(entity.OnligneId id) {
		log.debug("getting Onligne instance with id: " + id);
		try {
			Onligne instance = (Onligne) getSession().get("entity.Onligne", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Onligne> findByExample(Onligne instance) {
		log.debug("finding Onligne instance by example");
		try {
			List<Onligne> results = (List<Onligne>) getSession()
					.createCriteria("entity.Onligne").add(create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Onligne instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Onligne as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all Onligne instances");
		try {
			String queryString = "from Onligne";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
        public List findByNemuro(String s) {
		log.debug("finding all Onligne instances");
		try {
			String queryString = "from Onligne where numero_serie='"+s+"'";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
         public List findByIdOrder(int s) {
		log.debug("finding all Onligne instances");
		try {
			String queryString = "from Onligne where idorder="+s;
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Onligne merge(Onligne detachedInstance) {
		log.debug("merging Onligne instance");
		try {
			Onligne result = (Onligne) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Onligne instance) {
		log.debug("attaching dirty Onligne instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Onligne instance) {
		log.debug("attaching clean Onligne instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}